<?php

class Career_model extends CI_Model {
	
	function __construct()	{
      parent::__construct();
   }
	
   public function countRecord($where = '') {
   	
   	if(!$where)
   		return $this->db->count_all("job");
   	elseif($where === 'app') {
   		$this->load->database();
   		$this->db->select('*');
   		$this->db->from('job');
   		$this->db->where('admin', 1);
   		return $this->db->count_all_results();
   		}
   	elseif($where === 'uapp') {
   		$this->load->database();
   		$this->db->select('*');
   		$this->db->from('job');
   		$this->db->where('admin', 0);
   		return $this->db->count_all_results();
   		}
   		
   }
   
	public function record_count() {
        return $this->db->count_all("job");
    }
   
   public function show_all_jobs() {
	   	$this->load->database();
	   	$this->db->select('*');
	   	$this->db->from('job');
	   	$this->db->join('members', 'job.postedId = members.id');
	   	$this->db->where('admin', 1);
	   	$this->db->order_by("cdate", "asc");
	   	$query = $this->db->get();
	   	//print_r($this->db->last_query());
	   	return $query->result();
   }
   
   public function admin_show_all_jobs() {
	   	$this->load->database();
	   	$this->db->select('*');
	   	$this->db->from('job');
	   	$this->db->join('members', 'job.postedId = members.id');
	   	$this->db->order_by("cdate", "asc");
	   	if($this->session->userdata('status') == 'app')
	   	{
	   		$this->db->where('admin', 1);
	   	}
	   	else if($this->session->userdata('status') == 'uapp')
	   	{
	   		$this->db->where('admin', 0);
	   	}
	   	$query = $this->db->get();
	   	//print_r($this->db->last_query());
	   	return $query->result();
   }
   
   public function show_job($id) {
	   	$this->load->database();
	   	$this->db->select('*');
	   	$this->db->from('job');
	   	$this->db->join('members', 'job.postedId = members.id');
	   	$this->db->where('jobId', $id);
	   	$query = $this->db->get();
	   	return $query->result();
   }
   
   public function edit_job($jobId) {
   	$admin = 0;
   	$title = $this->security->xss_clean($this->input->post('title'));
   	$vacancy = $this->security->xss_clean($this->input->post('vacancy'));
   	$cdate = $this->common->dateformatsql($this->security->xss_clean($this->input->post('cdate')));
   	$elig = $this->security->xss_clean($this->input->post('elig'));
   	$profile = $this->security->xss_clean($this->input->post('profile'));
   	$desc = $this->security->xss_clean($this->input->post('desc'));
   	$UID = $this->security->xss_clean($this->input->post('UID'));
   	if(($this->input->post('admin')))
   	{
   		$admin = 1;
   	}
   	$contact = $this->security->xss_clean($this->input->post('mail'));
   	$data = array(
   			'title' => $title,
   			'vacancy' => $vacancy,
   			'cdate' => $cdate,
   			'elig' => $elig,
   			'profile' => $profile,
   			'desc' => $desc,
   			'postedId' => $UID,
   			'contact' => $contact,
   			'admin' => $admin
   	);
   
	   	$this->db->where('jobId', $jobId);
		$this->db->update('job', $data); 
   
   	return 1;
   }
   
   public function postjob() {
	   	$title = $this->security->xss_clean($this->input->post('title'));
	   	$vacancy = $this->security->xss_clean($this->input->post('vacancy'));
	   	$cdate = $this->common->dateformatsql($this->security->xss_clean($this->input->post('cdate')));
	   	$elig = $this->security->xss_clean($this->input->post('elig'));
	   	$profile = $this->security->xss_clean($this->input->post('profile'));
	   	$desc = $this->security->xss_clean($this->input->post('desc'));
	   	$UID = $this->security->xss_clean($this->input->post('UID'));
	   	$contact = $this->security->xss_clean($this->input->post('mail'));
	   	$odate = date('Y-m-d');
	   	$data = array(
	   			'title' => $title,
	   			'vacancy' => $vacancy,
	   			'odate' => $odate,
	   			'cdate' => $cdate,
	   			'elig' => $elig,
	   			'profile' => $profile,
	   			'desc' => $desc,
	   			'postedId' => $UID,
	   			'contact' => $contact
	   	);
	   	 
	  	$this->db->insert('job', $data); 
	   	 
	   	return 1;
   }
   
   
	
}

